clear

linestyles={'-',':','-.','--'};

%% pick scaling coefficients

models = {'', '_ces', '_frictionless', '_ces_no_adj_cost'};


Nfirms =  1 - [7.13]/100;

close all
for xyz = 1:4
    model = models{xyz};
    disp(model)

    eval(['x = load("../free_entry', model, '/eq_mit_entry.mat")'])

    eq_mit = x.eq_mit;
    glob   = x.glob;
    options = x.options;
    
    prods = repmat(exp(glob.sf(:,2)), 1, options.T);

  %  eval(['eq_mit = eq_mit_', model, ';'])

    adj = sum(eq_mit.mu,1);
    scx = pick_scale(adj, Nfirms);
   
   if xyz == 1
       Nfirms = log_linear_scale(adj, scx)/adj(end);
       Nfirms = Nfirms(1:50);
   end



    % compute cost-weighted markups
    ngdp = sum(eq_mit.mu.*eq_mit.p.*eq_mit.y);
    labor_bill = eq_mit.W'.*sum(eq_mit.l.*eq_mit.mu);
    labor_share = (labor_bill./ngdp); 
    
    set(0,'defaultaxesfontname','cambria math') % beautify the axes a bit
    set(0,'defaultTextFontName', 'cambria math')
       
    T = 15;

    subplot(2,3,1)
    hold on
    mass = sum(eq_mit.mu,1);
    plot(log_linear_scale_plot(mass, scx), 'LineWidth', 4, 'linestyle', linestyles{xyz}); xlim([1 T]); title('Mass of producers');
  %  plot(eq_mit.M); xlim([1 T])
  ytickformat('percentage')

    %plot(Ns, 'LineWidth', 4)
    if xyz == 4
        yline(0, '--')
        leg = legend('Baseline', 'CES', 'No Adjustment Cost', 'CES + No Adjustment Cost','', 'Location', 'Southeast', 'FontSize', 8)
    end
    
    subplot(2,3,5)
    plot(log_linear_scale_plot(eq_mit.C, scx), 'LineWidth', 4, 'linestyle', linestyles{xyz}); xlim([1 T]);  title('Output')
    hold on
    ytickformat('percentage')
    
    subplot(2,3,6)
    plot(log_linear_scale_plot(eq_mit.W, scx), 'LineWidth', 4, 'linestyle', linestyles{xyz}); xlim([1 T]); ylim([-3 0]); title('Wage')
    hold on
    ylim([-3 0])
    ytickformat('percentage')
    
    subplot(2,3,4)
    plot(log_linear_scale_plot(eq_mit.L, scx), 'LineWidth', 4, 'linestyle', linestyles{xyz}); xlim([1 T]); title('Employment')
    hold on
    ytickformat('percentage')
    ylim([-2.5 0])
    
    labor_share = 1./labor_share;
    
     subplot(2,3,2)
     plot((log_linear_scale_plot(labor_share, scx)), 'LineWidth', 4, 'linestyle', linestyles{xyz}); xlim([1 T]); title('Markup')
     hold on
    ytickformat('percentage')
    
    subplot(2,3,3)
    
    Ys    = repmat(eq_mit.C',glob.Nsf,1);
    Z     = sum(eq_mit.y./Ys./prods.*eq_mit.mu);
    tfp   = log_linear_scale(Z.^(-1), scx);
     
    
    plot(100*(tfp/tfp(end)-1), 'LineWidth', 4, 'linestyle', linestyles{xyz}); xlim([1 T]);
    hold on
    ylim(100*([.985 1]-1))
    ytickformat('percentage')
    
    title('Effective TFP')
    set(gcf,'units','points','position',[10,10,1000,600])
    set(findall(gcf,'-property','FontSize'),'FontSize',16)
    leg.FontSize = 10;
end

print('-dpng', 'figures/entry_cost_shock_4models.png')



